<?php

class trackVisits {

  public $user;
  public $visits;
  public $trees;
  public $totTrees;
  
  function trackVisits($user){
    $this->user = $user;
  }
  
  function addVisit(){
    global $database;
    if($database->checkVisitTime($this->user) < date("Y-m-d 00:00:00")){
      $database->addVisit($this->user);
    }
    $database->checkToAddTree($this->user);
    $this->visits = $database->checkVisits($this->user);
    $this->trees = $database->getTrees($this->user);
    $this->totTrees = $database->getTotalTrees();
    return $this->calculateVisitsLeft($this->visits);
  }
  
  function calculateVisitsLeft(){
    return constants::$totVisits - $this->visits;
  }

}

?>
